<template>
	<view class="all">
		<view class="title">
			已选标签（1/8）
		</view>
		<view class="list">
			<view class="box" :class="{active:item.type==1}" v-for="(item , index) in list" :key="index"
				@click="chose(item.value,index)">
				{{item.value}}
			</view>
		</view>
		<view class="last" @click="dele()">
			保存
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {},
				arr:[]
			};
		},
		onLoad() {
			this.getlabel()
		},
		methods: {

			async getlabel() {
				const res = this.$api("/business/user/user").then((res) => {
					console.log(res);
					console.log(res.data.data);
					if (res.data.code == 1) {
						this.list = res.data.data.personality_label
					}
				})
			},
			chose(item,index) {
				if (this.list[index].type == 0) {
					this.list[index].type = 1
				} else {
					this.list[index].type = 0
				}
			},
			dele() {
				console.log(this.list);
				this.list.forEach((item,index)=>{
					if(item.type==1){
						console.log(item.value);
						this.arr.push(item.value)
					}
				})
				const arr2=this.arr.join()

				this.$api("/business/user/profile",'post',{
					name:"",
					personality_label:arr2,
					avatar:"",
					life_photos:''
				}).then((res)=>{
					console.log(res);
					if(res.data.code==1){
						uni.$u.toast('编辑成功')
						this.getlabel()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.all {
		padding: 15px;

		.title {
			font-size: 15px;
			font-weight: bold;
			color: #333333;
			margin: 10px 0;
		}

		.list {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			margin: 20px 0;

			.box {
				background: #FFF8EE;
				border-radius: 16px;
				font-size: 14px;
				font-weight: 400;
				color: #999999;
				text-align: center;
				padding: 5px 10px;
				margin: 5px;
			}

			.active {
				background: #FB774B;
				border-radius: 16px;
				font-size: 14px;
				font-weight: 400;
				color: #fff;
				text-align: center;
				padding: 5px 10px;
				margin: 5px;
			}
		}

		.last {
			width: 70%;
			margin: 40px auto;
			color: #fff;
			background-color: #FB774B;
			font-size: 14px;
			border-radius: 20px;
			text-align: center;
			padding: 10px 0;
		}
	}
</style>